home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-18 | 8.3 KB | 269 lines | [TEXT/MMCC] |
- //
- // CTCPEndpoint.h
- //
- // TurboTCP library
- // TCP generic protocol interpreter
- //
- // Copyright © 1993-95, FrostByte Design / Eric Scouten
- //
-
- #pragma once
-
- #include "TurboTCP.buildflags.h"
- #include "UTurboTCP.h"
-
- #if TurboTCP_TCL
- #include "TCL.h"
- #endif
-
- class CTCPStream;
- class CTCPResolverCall;
-
-
- //***********************************************************
- //
- // TCP precedence values (used for SetPrecedence() method)
- //
-
- enum TCPPrecedence {
- precRoutine = 0,
- precPriority = 1,
- precImmediate = 2,
- precFlash = 3,
- precFlashOverride = 4,
- precCriticECP = 5,
- precInetControl = 6,
- precNetControl = 7
- };
- typedef enum TCPPrecedence TCPPrecedence;
-
-
- //***********************************************************
- //
- // ICMP report message types
- //
-
- enum ICMPType {
- icmpNetUnreach = 0,
- icmpHostUnreach = 1,
- icmpProtocolUnreach = 2,
- icmpPortUnreach = 3,
- icmpFragReqd = 4,
- icmpSourceRouteFailed = 5,
- icmpTimeExceeded = 6,
- icmpParmProblem = 7,
- icmpMissingOption = 8
- };
- typedef enum ICMPType ICMPType;
-
- //***********************************************************
- //
- // TCP termination reason codes
- //
-
- enum TCPTerminReason {
- tcpTermRemoteAbort = 2,
- tcpTermNetFailure = 3,
- tcpTermSecurityMismatch = 4,
- tcpTermTimeout = 5,
- tcpTermAbort = 6,
- tcpTermClose = 7,
- tcpTermServiceFailure = 8
- };
- typedef enum TCPTerminReason TCPTerminReason;
-
-
- //***********************************************************
-
- class CTCPEndpoint {
-
- // This mix-in class is provided to link your TCL classes with the TurboTCP CTCPStream
- // class. View this as a “connection session” helper. In a typical application, this class
- // (or a subclass of it) would be mixed with a CDocument or CDialogDirector.
-
- // This class does not implement any specific TCP protocol. You will need to subclass it
- // to provide the behaviors specific to the protocol you are implementing. You may want
- // to examine and use the CTelnetInterpreter class to see how this may be done.
-
- // This class provides most of the necessary behaviors for opening and closing a session.
- // It provides abstract methods for receiving data and handling various TCP notifications.
-
- // TurboTCP 1.0 users NOTE: This class replaces the CCollaborator link between CTCPStream and
- // CTCPSessionDoc which was existed in version 1.0. It *must* be included in your project.
-
- friend class CTCPStream;
- friend class CTCPResolverCall;
-
- #if TurboTCP_TCL
- TCL_DECLARE_CLASS;
- #endif
-
- public:
- CTCPEndpoint(unsigned short theDefaultPort,
- unsigned long recBufferSize = recReceiveSize,
- unsigned short autoReceiveSize = recAutoRecSize,
- unsigned short autoReceiveNum = recAutoRecNum,
- Boolean doUseCName = true); // TurboTCP 2.0: note new parameter sequence
- virtual ~CTCPEndpoint();
-
- // opening/closing session
-
- virtual void OpenUserHost(char* theHostName, unsigned short theDefaultPort,
- Boolean allowPortChange);
- virtual void OpenHost(unsigned long remoteHostIP, unsigned short remoteHostPort);
- virtual void Listen(unsigned long remoteHostIP, unsigned short remoteHostPort);
- virtual Boolean LocalClose(Boolean quitting);
- Boolean SessionEstablished();
-
- // sending data
-
- void SendBfrCpy(const void* theData, unsigned short theDataSize);
- void SendBfrNoCpy(const void* theData, unsigned short theDataSize, Boolean disposeWhenDone,
- Boolean notifyWhenDone);
-
- void SendChar(const char theChar);
- void SendCString(const char* theString);
- void SendPString(const unsigned char* theString);
-
- void SetNextPush();
- void SetNextUrgent();
-
- CTCPEndpoint& operator << (CTCPEndpoint& (*_F)(CTCPEndpoint&))
- { return ((*_F)(*this)); }
- friend inline CTCPEndpoint& operator << (CTCPEndpoint& s, const char* v)
- { s.SendCString(v); return s; }
- friend inline CTCPEndpoint& operator << (CTCPEndpoint& s, const unsigned char* v)
- { s.SendPString(v); return s; }
- friend inline CTCPEndpoint& operator << (CTCPEndpoint& s, char v)
- { s.SendChar(v); return s; }
-
- // configuration methods
-
- void SetDefaultPort(unsigned short newDefaultPort);
- void SetLocalHostPort(unsigned short newLocalPort);
- void SetOpenTimeout(unsigned short openMaxSeconds);
- void SetListenTimeout(unsigned short openMaxSeconds);
- void SetTypeOfService(Boolean lowDelay, Boolean highThroughput, Boolean highReliability);
- void SetPrecedence(TCPPrecedence newPrecedence);
- void SetDontFragment(Boolean newDontFragment);
- void SetTimeToLive(unsigned short newTimeToLive);
- void SetSecurity(unsigned short newSecurity);
-
- // selectors
-
- void GetRemoteHostName(char* hostStringBfr);
- unsigned long GetRemoteHostIP();
- unsigned short GetRemoteHostPort();
- unsigned long GetLocalHostIP();
- unsigned short GetLocalHostPort();
- unsigned short GetDefaultPort();
-
-
- protected:
-
- // state change notifications
-
- virtual void RemoteClose();
- virtual void StateChanged();
-
- // document/window naming
-
- virtual void SetWindowTitle(Str255 newTitle) {} // Override to set the window title to the given string.
- virtual void GetFileName(Str255 theName) // Override to return the file name of the session.
- { theName[0] = '\0'; }
-
- // error handling
-
- virtual short TCPErrorAlert(OSErr err, long message, short alertID, short parm3);
-
- // TCP/DNR notification routines — called by CTCPStream and CTCPResolverCall
- // Override some or all of these methods to respond to events as needed.
-
- virtual void HandleDataArrived(void* theData, unsigned short theDataSize, Boolean isUrgent) = 0;
- // ** MUST OVERRIDE **
-
- virtual void HandleClosed() {}
- virtual void HandleClosing(Boolean remoteClosing);
- virtual void HandleDataSent(void* theData, unsigned short theDataSize) {}
- virtual void HandleICMP(ICMPType reportType, unsigned short optionalAddlInfo,
- void* optionalAddlInfoPtr) {}
- virtual void HandleOpened();
- virtual void HandleOpenFailed(OSErr theResultCode);
- virtual void HandleSendFailed(void* theData, unsigned short theDataSize, OSErr theResultCode) {}
- virtual void HandleTCPError(OSErr theResultCode, short theCsCode);
- virtual void HandleTerminated(TCPTerminReason terminReason, Boolean aboutToDispose);
- virtual void HandleTimeout() {}
- virtual void HandleUnexpectedData() {}
- virtual void HandleUrgentBegin() {}
-
- virtual void HandleStrToAddr(struct hostInfo* theHostInfo);
- virtual void HandleAddrToName(struct hostInfo* theHostInfo);
- virtual void HandleHInfo(struct returnRec* theHInfo) {}
- virtual void HandleMXInfo(struct returnRec* theMXInfo) {}
-
-
- // configuration fields
- // Your subclass may change these variables to customize behaviors.
-
- Boolean useCName; // get host’s canonical name
- Boolean goAwayOnClose; // close window when session closes
- Boolean showFileName; // show filename in window titles
- Boolean showHostName; // show host name in window titles
- short untitledNumber; // serial number for untitled documents
-
-
- //----------------------
- // protected interface (TEMPORARY)
- // WARNING: these members will become private VERY SOON!
- // Do your best to get rid of references to these members!
- //
-
- protected:
-
- // informational fields
- // DO NOT change these values!
-
- CTCPStream* itsStream; // TCP stream for this document
- CTCPResolverCall* itsResolver; // TCP resolver for this document
- Boolean pendingOpenByName; // OpenUserHost has been issued
- unsigned short pendingPortNumber; // port number for OpenUserHost
- Boolean closeAndQuit; // closing windows to quit
-
- char hostCName[256]; // canonical name of host
- // if cnames not requested, is user’s name
- unsigned long hostAddress; // IP address of host
- unsigned short defaultPort; // default port number
- unsigned short actualPort; // current port number
- unsigned short localPort; // default local port number
-
- enum {
- ALRT_TCPOpenFailed = 23000,
- ALRT_TCPUnexpError = 23001,
- ALRT_TCPSendFailed = 23002,
- ALRT_TCPTerminated = 23003,
- ESTR_TerminBase = 23010,
-
- STR__WindowStrings = 23000,
- Wstr_NoSession = 1,
- Wstr_Separator = 2,
- Wstr_NotReadyPrefix = 3,
- Wstr_NotReadySuffix = 4,
- Wstr_Untitled = 5,
- Wstr_UntitledNoNumber = 6,
- Wstr_PortDelimiter = 7
- };
-
- };
-
-
- //***********************************************************
- //
- // Stream-like manipulators for CTCPEndpoint
- //
-
- CTCPEndpoint& endl(CTCPEndpoint& ep);
- CTCPEndpoint& local_IP(CTCPEndpoint& ep);
- CTCPEndpoint& remote_IP(CTCPEndpoint& ep);
- CTCPEndpoint& push(CTCPEndpoint& ep);
- CTCPEndpoint& urgent(CTCPEndpoint& ep);
-